<?php
require_once 'CMS/Util.php';
require_once 'CMS/Mvc/BaseController.php';
require_once 'CMS/Mvc/BaseUserController.php';
require_once 'CMS/UserCommon.php';
require_once 'CMS/User.php';
require_once 'CMS/Language.php'; //include thu vien language

//Người tạo : Nguyễn Huỳnh Đại Thành - Team 3
//Chỉnh sửa : Nguyễn Thanh Hải - Team 2
//Module 	: Lastest News
//Chức năng	: Show ra tất cả những News mới update

class LastestNews_IndexController{

	public function init(){
		parent::init();
	}
	//Action index thục hiện chức năng show thông tin của module
	public function indexAction(){
		
		/*========== Start Load Language ==========*/
		$language = new Language(APPLICATION_PATH . '/widgets/lastestnews');
		if(isset($_SESSION['language']))
		{
			$language_id = $_SESSION['language'];
			$tbLanguage = new Language_Model_Language();
			$name = $tbLanguage->getNameLanguage($language_id);
			$language->load($name['name']);
		}
		else
			$language->load('Default');		
		/*========== End Load Language ==========*/
	
		//Start------Check Input Parameter
		
		
		
		$path = APPLICATION_PATH."/widgets/lastestnews/";
		$xmlconfig = new SimpleXMLElement($path."config.xml",null,true);//Read config.xml
		//End--------Check Input Parameter
		
		//Start------Khai báo các parameter
		$tbNews = new LastestNews_Model_Things();
	
			
		$AllNews = $tbNews->getLastest(2,$xmlconfig->limit);
		$i = 0;
		foreach($AllNews as $News)
		{
			$title_lang=unserialize($News["title"]);
			if(isset($title_lang[$name['name']]))
				$AllNews[$i]["title"]=$title_lang[$name['name']];
			else
				$AllNews[$i]["title"]="------------------";
				$i++;
		}
		//End--------Khai báo các parameter
		//Start------Truyền parameter qua View
		/************ Start check user login *********/
		$session1 = new Zend_Session_Namespace('login.auth');
		if(isset($session1->id_user))
		{
			$this->view->login = "1";
		
			/************ Start check permission *********/
			$user = new User();
			$user->init();
			$hasmodify = $user->modifiy_widget($xmlconfig->name);
			$this->view->permission = $hasmodify;
			/************ End check user permission *********/
		}
		else 
		{
			
			$this->view->login = "0";
		}
		
		/************ End check user login *********/
		$titleXML = 'title'.$name['name'];
		if(isset($xmlconfig->$titleXML))
			$this->view->title = $xmlconfig->$titleXML;
		else
        	$this->view->title = $xmlconfig->titleDefault;
		$this->view->AllNews = $AllNews;
		$this->view->textviews 		= $language->get('text_views');
		//End--------Truyền parameter qua View
		
	}
	
}